vim9script noclear

export def SwitchHeaderSource()
   var filepath_nosuffix = fnamemodify(expand('%'), ':p:r')
   var suffix = fnamemodify(expand('%'), ':e')

   if suffix == 'h'
       suffix = 'cpp'
   elseif suffix == 'cpp'
       suffix = 'h'
   else
       echo '文件类型不支持'
   endif

   var filepath = filepath_nosuffix .. '.' .. suffix
   if filereadable(filepath)
       execute 'e ' .. filepath
   else
       echo '没有找到匹配的文件，或匹配的文件不可读'
   endif
enddef

